package com.cuijiao.emp.java.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author cuijiao
 *
 */
public class FileConsole {
    /**
     * 用文件充当控制台（可查看行数无限制）
     *
     * @param str
     */
    public static void print(String str) {
        File file = new File("E:\\console.txt");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        FileWriter fw = null;
        BufferedWriter bw = null;
        try {
            fw = new FileWriter(file, true);// 可追加内容
            bw = new BufferedWriter(fw);
            bw.write(str);
            bw.newLine();// 换行
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                if (bw != null) {
                    bw.close();
                    bw = null;
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
